
#include "DrawingStrategy.h"

#include "DrawingStrategyCollection.h"
#include "Query.h"

void DrawingStrategyCollection::setDiscardStrategy(DiscardStrategy* strategyRef) {
    for (int i = 0; i < numStrategies; i++) {
        collection[i]->setDiscardStrategy(strategyRef);
    }
}

bool DrawingStrategyCollection::pickFromDiscard(CCardStack* hand, const GameState* state) {
    int voteCount[2] = {0};
    int voteOf[numStrategies];
    for (int i = 0; i < numStrategies; i++) {
        voteOf[i] = collection[i]->pickFromDiscard(hand, state) ? 1 : 0;
        voteCount[voteOf[i]] += collection[i]->getDecisionCertainty() * collection[i]->getWeight();
    }
    bool decision;
    if (voteCount[0] > voteCount[1]) {
        decision = false;
    }
    else if (voteCount[0] < voteCount[1]) {
        decision = true;
    }
    else {
        int maxWeight = 0;
        for (int i = 0; i < 2; i++) {
            int vote = i;
            for (int j = 0; j < numStrategies; j++) {
                int strategyWeight = collection[j]->getWeight();
                if (voteOf[j] == vote && strategyWeight > maxWeight) {
                    maxWeight = strategyWeight;
                    decision = (vote == 0) ? false : true;
                }
            }
        }
    }
    return decision;
}

int DrawingStrategyCollection::getDecisionCertainty() {
    return 0;
}

void DrawingStrategyCollection::opponentMove(int opponent, const Move& move) {
    for (int i = 0; i < numStrategies; i++) {
        collection[i]->opponentMove(opponent, move);
    }
}
